package com.admin.business.electionPaymentOrder;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 支付订单记录表补选委员
 * @create: 2023-10-28 09:27:23
 **/
@Service("electionPaymentOrderService")
@Slf4j
public class ElectionPaymentOrderService{

    @Resource
    ElectionPaymentOrderDao electionPaymentOrderDao;

    /**
     * 添加支付订单记录表补选委员,获取id数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - election_id:解聘记录id
     *                   - order_name:订单名称
     *                   - order_money:点单金额
     *                   - order_state:订单状态：1已支付，0未支付，2支付中
     *                   - order_type:支付类型：1微信，0支付宝
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return addElectionPaymentOrder(CDO cdoRequest) {
        electionPaymentOrderDao.addElectionPaymentOrder(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新支付订单记录表补选委员数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - election_id:解聘记录id
     *                   - order_name:订单名称
     *                   - order_money:
     *                   - order_state:订单状态：1已支付，0未支付，2支付中
     *                   - order_type:支付类型：1微信，0支付宝
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return updateElectionPaymentOrderById(CDO cdoRequest) {
        electionPaymentOrderDao.updateElectionPaymentOrderById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除支付订单记录表补选委员数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return deleteElectionPaymentOrderById(CDO cdoRequest){
        int count = electionPaymentOrderDao.deleteElectionPaymentOrderById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除支付订单记录表补选委员数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return deleteElectionPaymentOrder(CDO cdoRequest) {
        int count = electionPaymentOrderDao.deleteElectionPaymentOrder(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取支付订单记录表补选委员数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return getElectionPaymentOrderById(CDO cdoRequest) {
        CDO cdoMapperResult = electionPaymentOrderDao.getElectionPaymentOrderById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取支付订单记录表补选委员数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return getElectionPaymentOrderListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = electionPaymentOrderDao.getElectionPaymentOrderListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = electionPaymentOrderDao.getElectionPaymentOrderCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取支付订单记录表补选委员数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return getElectionPaymentOrderListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = electionPaymentOrderDao.getElectionPaymentOrderListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = electionPaymentOrderDao.getElectionPaymentOrderCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
